#!/bin/bash
#function: install zookeeper
#parmeter:QQ群496379594
#author:
#version: 1.1
#Test: CentOS6 

useverison=zookeeper-3.4.11
yum install wget -y 

wget http://xxxx/othortool/zookepper/${useverison}.tar.gz

mkdir -p /usr/local/zookeeper/{data,log}

tar -zxf ${useverison}.tar.gz
cd ${useverison}

cp -rv  bin conf docs src ${useverison}.jar lib /usr/local/zookeeper/
yum install java-1.8.0-openjdk -y


cd /usr/local/zookeeper/conf
cp zoo_sample.cfg zoo.cfg
sed -i  '/^dataDir/s/\/tmp\/zookeeper/\/usr\/local\/zookeeper\/data/' zoo.cfg

sed -i '/ZOO_LOG_DIR=/s/ZOO_LOG_DIR="."/ZOO_LOG_DIR=${ZOOKEEPER_PREFIX}\/log/' ../bin/zkEnv.sh

useradd  -s /sbin/nologin zookeeper
chown -R zookeeper:zookeeper /usr/local/zookeeper

cp /usr/local/zookeeper/src/packages/rpm/init.d/zookeeper /etc/init.d/
chmod 755 /etc/init.d/zookeeper
chkconfig --add zookeeper
sed -i '/\/usr\/libexec/s/\/usr\/libexec/\/usr\/local\/zookeeper\/bin/' /etc/init.d/zookeeper 
sed -i '/zkServer.sh/s/zkServer.sh/\/usr\/local\/zookeeper\/bin\/zkServer.sh/' /etc/init.d/zookeeper 
sed -i '/PIDFILE="${ZOOPIDFILE}"/s/PIDFILE="${ZOOPIDFILE}"/PIDFILE=\/usr\/local\/zookeeper\/data\/zookeeper_server.pid/' /etc//init.d/zookeeper
#cd /usr/local/zookeeper/bin
#sh zkEnv.sh
#sh  zkServer.sh start 
#sh  zkServer.sh status 

